const config = require('../config/config')
const service = require('../service/service')
const util = require('util')

async function getUid () {
  let uid = config.getConf('uid')
  if (!uid) {
    console.log('generating uid...')
    uid = await service.genidWithLocalid()
    console.log('generated saving...')
    config.setConf('uid', uid)
    config.saveConf()
    console.log(`saved uid is ${uid}`)
  }
  return uid
}

async function sleep (time) {
  return new Promise((resolve, reject) => {
    setTimeout(() => {
      resolve(time)
    }, time)
  })
}

module.exports = {
  ...util,
  getUid,
  sleep
}
